#导入flask
from flask import Blueprint,request
#导入app
from flask import current_app as app
#导入excal操作导包
from xlrd import open_workbook


#导入数据库
from db import db1

#导入os模块
import os

#导入封装好的文件操作模块
from utils.myfile import myf

bp_comany=Blueprint('comany',__name__)



@bp_comany.route('/test')
async def test():
    str='请求ip'+request.remote_addr+'请求的url'+request.url+'错误信息'+'\n'
    app.logger.error(str)
    return 'ok'





#上传excel,并导入数据库
@bp_comany.route('/upload',methods=['POST'])
def upload():
    #获取文件
    file=request.files['file']
    newname=myf.rename(file.filename)
    #上传文件
    file.save(os.path.join('./static/files/'+newname))
    #打开文件读取
    name='./static/files/'+newname
    bk=open_workbook(name,encoding_override='utf-8')
    sh=bk.sheets()[0]
    nrows=sh.nrows
    ncols=sh.ncols
    for i in range(1,nrows):
        row_date=sh.row_values(i)
        print(row_date[0])
        print(row_date[1])
    return 'ok'
    #封装数据写入数据库
